package cn.itcast.controller;

import cn.itcast.domain.Student;
import cn.itcast.service.StudentService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/student")
@ResponseBody
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public List<Student> findAll()throws Exception{
        List<Student> list = studentService.findAll();
        System.out.println(list);
        return list;
    }
    @PostMapping
    public void save( Student student)throws Exception{
        studentService.save(student);
    }
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id)throws Exception{
        studentService.delete(id);
    }
    @PutMapping
    public void update(Student student)throws Exception{
        studentService.update(student);
    }
    @GetMapping("/{id}")
    public List<Student> findBy(@PathVariable Integer id)throws Exception{
        List<Student> list = studentService.findBy(id);
        return list;
    }

}